<template>
  <el-row :gutter="10" class="panel-group">
          <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
            <div class="card-panel">
              <div class="card-number">
                <count-to :start-val="0" :end-val="zxSum" :duration="1000" class="card-panel-num" /><span class="txt">人</span>
              </div>
              <div class="card-txt">当前在线总数 (台)</div>
            </div>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
            <div class="card-panel">
              <div class="card-number">
                <count-to :start-val="0" :end-val="sbSum" :duration="1000" class="card-panel-num" />人
              </div>
              <div class="card-txt">设备总数 (台)</div>
            </div>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
            <div class="card-panel">
              <div class="card-number">
                <count-to :start-val="0" :end-val="jhSum" :duration="1000" class="card-panel-num" />人
              </div>
              <div class="card-txt">激活总数 (台)</div>
            </div>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
            <div class="card-panel">
              <div class="card-number">
                <count-to :start-val="0" :end-val="jsSum" :duration="1000" class="card-panel-num" />人
              </div>
              <div class="card-txt">解锁设备数 (台)</div>
            </div>
          </el-col>
        </el-row>
</template>

<script>
import CountTo from 'vue-count-to'
import { SumCount, activateMacNum, OnlineCount, lockCount, getUserAppSum } from "@/api/dashboard.js";
export default {
  props: {
    sbId: {
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      sbSum: 0,
      jhSum: 0,
      zxSum: 0,
      jsSum: 0,
      appNume: 0
    }
  },
  components: {
    CountTo
  },
  watch: {
    sbId(name, value) {
      this.getSumCount(name)
      this.getactivateMacNum(name)
      this.getOnlineCount(name)
      this.getlockCount(name)
      this.getUserAppSums(name)
    }
  },
  created() {
    this.getSumCount()
    this.getactivateMacNum()
    this.getOnlineCount()
    this.getlockCount()
    this.getUserAppSums()
    //console.log('---------身份',localStorage.getItem("auth_group_id"),localStorage.getItem("roleName"))
  },
  methods: {
    //跳转
    gotoRouter(path) {
      if (localStorage.getItem("auth_group_id") == 7 && localStorage.getItem("roleName") == '普通用户') return
      console.log('路由', path)
      this.$router.push(path)
    },
    getSumCount(id = localStorage.getItem("ID")) {
      SumCount({ userId: id }).then(res => {
        this.sbSum = res.data
      }).catch(err => {
        this.sbSum = 0
      })
    },
    getactivateMacNum(id = localStorage.getItem("ID")) {
      activateMacNum({ userId: id }).then(res => {
        this.jhSum = res.data
      }).catch(err => {
        this.jhSum = 0
      })
    },
    getOnlineCount(id = localStorage.getItem("ID")) {
      OnlineCount({ userId: id }).then(res => {
        this.zxSum = res.data
      }).catch(err => {
        this.zxSum = 0
      })
    },
    getlockCount(id = localStorage.getItem("ID")) {
      lockCount({ userId: id }).then(res => {
        this.jsSum = res.data
      }).catch(err => {
        this.jsSum = 0
      })
    },
    //获取app数量
    getUserAppSums(id = localStorage.getItem("ID")) {
      getUserAppSum({ userId: id }).then(res => {
        this.appNume = res.data
      }).catch(err => {
        this.appNume = 0
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.bj_sum1 {
  // background: url(../../../../assets/images/dashboard1.png);
  background-image: -webkit-linear-gradient(
    90deg,
    rgba(224, 62, 76) 0%,
    rgba(255, 191, 0) 100%
  );
}
.bj_sum2 {
  //background: url(../../../../assets/images/dashboard2.png);
  background-image: -webkit-linear-gradient(90deg, #f857a6 0%, #ff5858 100%);
}
.bj_sum3 {
  //background: url(../../../../assets/images/dashboard3.png);
  background-image: -webkit-linear-gradient(
    90deg,
    rgba(116, 21, 219) 0%,
    rgba(55, 162, 255) 100%
  );
}
.bj_sum4 {
  //background: url(../../../../assets/images/dashboard4.png);
  background-image: -webkit-linear-gradient(
    90deg,
    rgba(77, 119, 255) 0%,
    rgba(0, 221, 255) 100%
  );
}
.bj_sum5 {
  //background: url(../../../../assets/images/dashboard5.png);
  background-image: -webkit-linear-gradient(
    90deg,
    rgba(1, 191, 236) 0%,
    rgba(128, 255, 165) 100%
  );
}
.sbs {
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: top center;
  overflow: hidden;
}
.panel-group {

  .card-panel-col {
    margin-bottom: 20px;
  }

  .card-panel {
    height: 130px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    border-color: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    background-clip: padding-box;

    .icon-people {
      color: #fff;
    }

    .icon-message {
      color: #fff;
    }

    .icon-money {
      color: #fff;
    }

    .icon-shopping {
      color: #fff;
    }
    .icon-appshop {
      color: #fff;
    }

    .card-panel-icon-wrapper {
      float: right;
      margin: 26px 0 0 0;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: right;
      font-size: 48px;
    }

    .card-panel-description {
      float: left;
      font-weight: bold;
      margin: 44px 44px 44px 20px;
      margin-right: 0px;

      .card-panel-text {
        line-height: 18px;
        //color: rgba(0, 0, 0, 0.45);
        font-size: 12px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 24px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
.card-panel {
  background: url(../../../../assets/images/dashboard12.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: top center;
  text-align: center;
  padding-top: 30px;
  .card-number {
    font-size: 26px;
    margin-bottom: 10px;
    .txt {
      font-size: 20px;
    }
  }
  .card-txt{
    font-size: 12px;
    background-image: -webkit-linear-gradient( 90deg, rgba(77, 119, 255) 0%,rgba(0, 221, 255) 100% );
    padding: 6px 0;
    border-radius: 3px;
    margin: 0 20px;
  }
}
</style>

<style scoped>
/deep/ .el-col-lg-4-8 {
  width: 20%;
}

@media only screen and (min-width: 1200px) {
  /deep/.el-col-lg-4 {
    width: 19.99%;
  }
}
</style>